<?php
/**
 * Created by PhpStorm.
 * User: liupengfei
 * Date: 2017/9/1
 * Time: 14:22
 */
header('Content-type:text/html;charset=utf-8');
require_once 'XunSearch.php';
require_once 'Model.php';






?>

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .key{
            color: #D0021B;
            /*font-weight: bold;*/
        }
        p{
            border: 1px solid darkgray;
        }
        span{
            font-size: 14px;
        }

    </style>
</head>
<body>

<?php

$keyword = isset($_GET['key']) ? $_GET['key'] : '';

$configPath = dirname(__FILE__) . '/sdk/php/app/';

$xunSearch = new XunSearch($configPath. 'demo.ini');

$res = $xunSearch->search($keyword);
$data = $res['data'];
$count = $res['count'];

if (!empty($data) &&count($data) >=1) {
    echo '搜索结果：关键词 <span class="key">'.$keyword.'</span><br/>';
    foreach ($data as $doc) {

        $subject = $xunSearch->getSearch()->highlight($doc->title);
        $content = $xunSearch->getSearch()->highlight($doc->content);
//    $subject = $doc->title;
        $result = <<< RES
    <p>标题：$subject<br/>
    <span>内容：$content</span>
    </p>
<br/>
RES;

        echo $result;
    }


} else {

//    $corrected = $xunSearch->getSearch()->getCorrectedQuery('kecheng');
    $expand = $xunSearch->expanded($keyword);
    var_dump($expand);exit();
    if (count($corrected) !== 0)
    {
        echo "您是不是要找：\n";
        foreach ($corrected as $word)
        {
            echo $word . "\n";
        }
    }



}


?>

</body>
</html>

